home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Simulation / PDP-8 Simulator / Source Code / GE_Utilities.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-09-13  |  4.9 KB  |  248 lines  |  [TEXT/KAHL]

  1. /****************************************************************************************
  2. *
  3. *            GE_Utilities.c        Useful odd bits 
  4. *
  5. *            created 1/7/91 from recoverd files
  6. *            23/12/91    IsAResource function added.
  7. *            19/2/92        copied for use with generic editor.
  8. *
  9. ****************************************************************************************/
  10.  
  11. #include     "PDPGlobalEqu.p"
  12. #include    "QDOffscreen.h"
  13. #include "GE_Utilities.proto.h"
  14.  
  15.  
  16.  
  17. CopyString(Ptr s1,Ptr s2)
  18. {        
  19.     short    byteCount;
  20.     
  21.     byteCount=*s1+1;
  22.     BlockMove(s1,s2,byteCount);
  23. }
  24.  
  25.  
  26. ConcatString(Ptr s1,Ptr s2)
  27. {
  28.     /* given pointers to two pascal strings, this function concatenates the characters of
  29.         s2 on to the end of s1. No range checking is performed. */
  30.         
  31.     short    byteCount,offset;
  32.     Ptr        temp;
  33.     
  34.     temp=s1;                        /* remember old pointer         */
  35.     offset=*s1+1;                    /* length of first string         */
  36.     s1+=offset;                        /* point at end of string +1     */
  37.     byteCount=*s2;                       /* length of second string        */
  38.     s2++;                            /* first char of second string    */
  39.     BlockMove(s2,s1,byteCount);        /* copy chars                    */
  40.     *temp=offset+byteCount-1;        /* update length                */
  41. }
  42.  
  43.  
  44. SetWatchCursor(void)
  45. {
  46.     /* call to set watch cursor whenever a lengthy operation is to be called. The normal
  47.         AdjustCursor call will automatically return the cursor to its correct appearance
  48.         once the operation has terminated. */
  49.         
  50.     CursHandle    watch;
  51.     
  52.     watch=GetCursor(watchCursor);
  53.     if (watch!=NIL)
  54.         SetCursor(*watch);
  55. }
  56.  
  57.  
  58. short ShiftDown(void)
  59. {
  60.     /* returns TRUE if shift key down */
  61.     
  62.     KeyMap        theKeys;
  63.     
  64.     GetKeys(&theKeys);
  65.     return(theKeys[1] & 1);
  66. }
  67.     
  68.         
  69. short OptionDown(void)
  70. {
  71.     /* returns TRUE if option key down */
  72.     
  73.     KeyMap        theKeys;
  74.     
  75.     GetKeys(&theKeys);
  76.     return(theKeys[1] & 4);
  77. }
  78.  
  79.  
  80. short CommandDown(void)
  81. {
  82.     /* returns TRUE if command key down */
  83.     
  84.     KeyMap        theKeys;
  85.     
  86.     GetKeys(&theKeys);
  87.     return(theKeys[1] & 32768);
  88. }
  89.  
  90.  
  91. short ControlDown(void)
  92. {
  93.     /* returns TRUE if control key down */
  94.     
  95.     KeyMap        theKeys;
  96.     
  97.     GetKeys(&theKeys);
  98.     return(theKeys[1] & 8);
  99. }
  100.  
  101.  
  102. CentreRects(Rect *r1,Rect *r2)
  103. {
  104.     /* Offsets the coordinates of r2 so that it is centred with respect to r1. r1 is not
  105.         changed. Rectangles can be different sizes or same size */
  106.     
  107.     int        dH,dV;
  108.     
  109.     dH=((r1->right-r1->left)-(r2->right-r2->left))/2 - r2->left + r1->left;
  110.     dV=((r1->bottom-r1->top)-(r2->bottom-r2->top))/2 - r2->top  + r1->top;
  111.     OffsetRect(r2,dH,dV);
  112. }
  113.  
  114.  
  115. long GetNudgeDistance(void)
  116. {
  117.     /* if any of the arrow keys are down, the function returns the equivalent offset as
  118.         its result as if it was a pixel offset. HiWord is vertical offset, LoWord is
  119.         horizontal. If no keys down it returns zero. Can be used to implement graphic
  120.         nudging with the arrow keys. */
  121.         
  122.     KeyMap        theKeys;
  123.     long        dH,dV;
  124.     
  125.     GetKeys(&theKeys);
  126.     dH=0;dV=0;
  127.     if (theKeys[3] & 64)
  128.         dV=0x0000FFFF;
  129.     if (theKeys[3] & 32)
  130.         dV=1;
  131.     if (theKeys[3] & 8)
  132.         dH=0x0000FFFF;
  133.     if (theKeys[3] & 16)
  134.         dH=1;
  135.     return((long)(dV <<16 | dH));    
  136. }
  137.  
  138.  
  139. DebugKeys(void)
  140. {
  141.     KeyMap        theKeys;
  142.     Str255        kStr;
  143.     Rect        kBox;
  144.     
  145.     GetKeys(&theKeys);
  146.     NumToString(theKeys[3],&kStr);
  147.     SetRect(&kBox,20,40,100,60);
  148.     TextBox(&kStr[1],kStr[0],&kBox,teJustLeft);
  149. }
  150.  
  151.  
  152. SetDefaultOpColour(CGrafPtr  theWindow)
  153. {
  154.     /* sets OpColor of port to 50% grey */
  155.     RGBColor        blendWeight;
  156.     CGrafPtr        savePort;
  157.     GDHandle        saveDevice;
  158.     
  159.     
  160.     GetGWorld(&savePort,&saveDevice);
  161.     SetGWorld(theWindow,saveDevice);
  162.     blendWeight.red = blendWeight.green = blendWeight.blue = 0x7FFF;
  163.     OpColor(&blendWeight);
  164.     SetGWorld(savePort,saveDevice);
  165. }
  166.  
  167.  
  168. AlignToZero(Rect *theRect)
  169. {
  170.     /* Offsets rect so that it's top,left coordinate is 0,0. Size is unchanged. */
  171.     
  172.     OffsetRect(theRect,-theRect->left,-theRect->top);
  173. }
  174.  
  175.  
  176. MarkForUpdate(WindowPtr theWindow)
  177. {
  178.     /* invalidates the entire portrect of the window specified */
  179.     GrafPtr        savePort;
  180.     
  181.     if (theWindow!=NIL) {
  182.         GetPort(&savePort);
  183.         SetPort(theWindow);
  184.         InvalRect(&thePort->portRect);
  185.         SetPort(savePort);
  186.     }
  187. }
  188.  
  189.  
  190. AlignRgnToZero(RgnHandle theRgn)
  191. {
  192.     /* offsets region to align top, left to 0,0 */
  193.     Rect rB;
  194.     
  195.     if (theRgn!=NIL) {
  196.         rB=(**theRgn).rgnBBox;
  197.         OffsetRgn(theRgn,-rB.left,-rB.top);
  198.     }
  199. }
  200.  
  201.  
  202. SetIndMenuItem(MenuHandle theMenu,int theItem,int strListID,int strListItem)
  203. {
  204.     /* sets the menu item specified to the string in the string list specified */
  205.     Str255    mString;
  206.     
  207.     GetIndString(&mString,strListID,strListItem);
  208.     if (mString[0]>0 && theMenu!=NIL)
  209.         SetItem(theMenu,theItem,&mString);
  210. }
  211.  
  212.  
  213. SetIndParamText(int strListID,int strListItem)
  214. {
  215.     /* sets first param text item to the string in the string list specified */
  216.     Str255    mString;
  217.     
  218.     GetIndString(&mString,strListID,strListItem);
  219.     ParamText(&mString,"\p","\p","\p");
  220. }
  221.  
  222.  
  223. DrawIndString(int strListID,int strListItem)
  224. {
  225.     /* calls drawstring with indexed string specified */
  226.     
  227.     Str255    mStr;
  228.     
  229.     GetIndString(&mStr,strListID,strListItem);
  230.     DrawString(&mStr);
  231. }
  232.  
  233.  
  234. int IsAResource(Handle theRes)
  235. {
  236.     /* returns true if given handle is a resource, else false */
  237.     long     temp;
  238.     
  239.     temp = RsrcMapEntry(theRes);
  240.     if (ResError()==resNotFound)
  241.         return(FALSE);
  242.     else
  243.         return(TRUE);
  244. }
  245.  
  246.  
  247.  
  248.